#include "misc.h"

extern char* help;
extern char* welcom;
extern sqlite3 *ReadingDatabase;
extern sqlite3 *MainDatabase;

CONFIG config = {0};

int main()
{
	//加载配置参数
	config.option_choice_num = CONFIG_OPTION_MODE_CHOICE_NUM;
	config.option_pro_limit = CONFIG_OPTION_MODE_PROFICIENCY_LIMIT;
	config.spell_pro_limit = CONFIG_SPELL_MODE_PROFICIENCY_LIMIT;
	config.circulate_num = CONFIG_CIRCULATE_TIME;
	config.is_compile_readline = false;
	config.is_reverse_option = false;
	config.is_record_fillblank = false;
	memcpy(config.words_txt,CONFIG_WORDS_TXT_NAME,strlen(CONFIG_WORDS_TXT_NAME));
	memcpy(config.reading_txt,CONFIG_READING_MATERIAL_TXT_NAME,strlen(CONFIG_READING_MATERIAL_TXT_NAME));
	memcpy(config.fillBlank_txt,CONFIG_FILL_BLANK_REQ,strlen(CONFIG_FILL_BLANK_REQ));

	
#ifdef CONFIG_READLINE_COMPILE
	config.is_compile_readline = true;
#endif //CONFIG_READLINE_COMPILE
#ifdef CONFIG_REVERSE_OPTION_MODE
	config.is_reverse_option = true;
#endif // CONFIG_REVERSE_OPTION_MODE
#ifdef CONFIG_RECORD_FILL_BLANK
	config.is_record_fillblank = true;
#endif // CONFIG_RECORD_FILL_BLANK

	// 设置随机数的种子
    srand(time(NULL));

	// char buf[]
	// read_config("/etc/justDoIt.conf","MainDatabase_dir",);
	//打开主词汇数据库
	if( SQLITE_OK != sqlite3_open(CONFIG_MAIN_DATABASE_NAME, &MainDatabase) ){
		sqlite3_errmsg(MainDatabase);
		printf("open %s failed.\n",CONFIG_MAIN_DATABASE_NAME);
		perror("");
		return -1;
	}

	//打开阅读材料数据库
	if( SQLITE_OK != sqlite3_open(CONFIG_READING_MATERIAL_DATABASE_NAME, &ReadingDatabase) ){
		sqlite3_errmsg(ReadingDatabase);
		printf("open %s failed.\n",CONFIG_READING_MATERIAL_DATABASE_NAME);
		perror("");
		return -1;
	}

	//do_ui_display(db);
	printf("%s\n",welcom);
    printf("%s\n",help);
	show_progress(MainDatabase);

    console_ex(MainDatabase);

	if(SQLITE_OK != sqlite3_close(MainDatabase) && SQLITE_OK != sqlite3_close(ReadingDatabase)){
		printf("数据库关闭失败\n");
	}else
		printf("OK\n");

	return 0;
}